package day16.test01;

import java.io.*;
import java.net.Socket;

/**
 * @author Xiao
 * @date 2021/8/10
 */
public class ClientDemo {
    /**
     * 1. 将上课讲的网络编程案例：文件上传线程池最终版，实现一遍。
     */
    public static void main(String[] args) throws IOException {
        Socket so = new Socket("localhost", 12321);
        //读入本地文件，写出至服务器
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(
                "homework\\src\\day16\\test01\\Beauty.JPG"));
        BufferedOutputStream bos = new BufferedOutputStream(so.getOutputStream());
        int b;
        while ((b = bis.read()) != -1) {
            bos.write(b);
        }
        bos.flush();
        so.shutdownOutput();
        //读入服务器反馈
        BufferedReader br = new BufferedReader(new InputStreamReader(so.getInputStream()));
        String s;
        while ((s = br.readLine()) != null) {
            System.out.println(s);
        }
        bos.close();
        so.close();

    }
}
